<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
 <head>
  <meta http-equiv="content-type" content="text/html; charset=UTF-8">
  <title>Deflate a string</title>
<link media="all" rel="stylesheet" type="text/css" href="styles/03e73060321a0a848018724a6c83de7f-theme-base.css" />
<link media="all" rel="stylesheet" type="text/css" href="styles/03e73060321a0a848018724a6c83de7f-theme-medium.css" />

 </head>
 <body class="docs"><div class="navbar navbar-fixed-top">
  <div class="navbar-inner clearfix">
    <ul class="nav" style="width: 100%">
      <li style="float: left;"><a href="function.gzdecode.html">« gzdecode</a></li>
      <li style="float: right;"><a href="function.gzencode.html">gzencode »</a></li>
    </ul>
  </div>
</div>
<div id="breadcrumbs" class="clearfix">
  <ul class="breadcrumbs-container">
    <li><a href="index.html">PHP Manual</a></li>
    <li><a href="ref.zlib.html">Zlib 函数</a></li>
    <li>Deflate a string</li>
  </ul>
</div>
<div id="layout">
  <div id="layout-content"><div id="function.gzdeflate" class="refentry">
 <div class="refnamediv">
  <h1 class="refname">gzdeflate</h1>
  <p class="verinfo">(PHP 4 &gt;= 4.0.4, PHP 5, PHP 7, PHP 8)</p><p class="refpurpose"><span class="refname">gzdeflate</span> &mdash; <span class="dc-title">Deflate a string</span></p>

 </div>
 <div class="refsect1 description" id="refsect1-function.gzdeflate-description">
  <h3 class="title">说明</h3>
  <div class="methodsynopsis dc-description">
   <span class="methodname"><strong>gzdeflate</strong></span>(<span class="methodparam"><span class="type">string</span> <code class="parameter">$data</code></span>, <span class="methodparam"><span class="type">int</span> <code class="parameter">$level</code><span class="initializer"> = -1</span></span>, <span class="methodparam"><span class="type">int</span> <code class="parameter">$encoding</code><span class="initializer"> = <strong><code>ZLIB_ENCODING_RAW</code></strong></span></span>): <span class="type"><span class="type">string</span>|<span class="type"><span class="type false">false</span></span></span></div>

  <p class="para rdfs-comment">
   This function compresses the given string using the <code class="literal">DEFLATE</code>
   data format.
  </p>
  <p class="para">
   For details on the DEFLATE compression algorithm see the document
   &quot;<a href="http://www.faqs.org/rfcs/rfc1951" class="link external">&raquo;&nbsp;DEFLATE Compressed Data Format
   Specification version 1.3</a>&quot; (RFC 1951).
  </p>
 </div>

 <div class="refsect1 parameters" id="refsect1-function.gzdeflate-parameters">
  <h3 class="title">参数</h3>
  <p class="para">
   <dl>
    
     <dt>
<code class="parameter">data</code></dt>

     <dd>

      <p class="para">
       The data to deflate.
      </p>
     </dd>

    
    
     <dt>
<code class="parameter">level</code></dt>

     <dd>

      <p class="para">
       The level of compression. Can be given as 0 for no compression up to 9
       for maximum compression. If not given, the default compression level will
       be the default compression level of the zlib library.
      </p>
     </dd>

    
    
     <dt>
<code class="parameter">encoding</code></dt>

     <dd>

      <p class="para">
       One of <strong><code>ZLIB_ENCODING_*</code></strong> constants.
      </p>
     </dd>

    
   </dl>

  </p>
 </div>

 <div class="refsect1 returnvalues" id="refsect1-function.gzdeflate-returnvalues">
  <h3 class="title">返回值</h3>
  <p class="para">
   The deflated string or <strong><code>false</code></strong> if an error occurred.
  </p>
 </div>

 <div class="refsect1 examples" id="refsect1-function.gzdeflate-examples">
  <h3 class="title">范例</h3>
  <p class="para">
   <div class="example" id="example-878">
    <p><strong>示例 #1 <span class="function"><strong>gzdeflate()</strong></span> example</strong></p>
    <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br />$compressed&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">gzdeflate</span><span style="color: #007700">(</span><span style="color: #DD0000">'Compress&nbsp;me'</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">9</span><span style="color: #007700">);<br />echo&nbsp;</span><span style="color: #0000BB">$compressed</span><span style="color: #007700">;<br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</code></div>
    </div>

   </div>
  </p>
 </div>


 <div class="refsect1 seealso" id="refsect1-function.gzdeflate-seealso">
  <h3 class="title">参见</h3>
  <p class="para">
   <ul class="simplelist">
    <li class="member"><span class="function"><a href="function.gzinflate.html" class="function" rel="rdfs-seeAlso">gzinflate()</a> - Inflate a deflated string</span></li>
    <li class="member"><span class="function"><a href="function.gzcompress.html" class="function" rel="rdfs-seeAlso">gzcompress()</a> - Compress a string</span></li>
    <li class="member"><span class="function"><a href="function.gzuncompress.html" class="function" rel="rdfs-seeAlso">gzuncompress()</a> - Uncompress a compressed string</span></li>
    <li class="member"><span class="function"><a href="function.gzencode.html" class="function" rel="rdfs-seeAlso">gzencode()</a> - Create a gzip compressed string</span></li>
   </ul>
  </p>
 </div>

</div></div></div></body></html>